package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// Area 地区定义
type Area struct {
	ID       string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	Name     string `json:"name" gorm:"column:name;type:string;size:40;comment:名称"`
	Level    int    `json:"level" gorm:"column:level;type:int;size:8;comment:级别 1-省份 2-市 3-区 4-街道/乡"`
	ParentID string `json:"parent_id" gorm:"column:parent_id;type:int;size:64;comment:父级id"`
}

// TableName 表名称
func (a *Area) TableName() string {
	return "area"
}

// BeforeCreate 自增id
func (a *Area) BeforeCreate(tx *gorm.DB) (err error) {
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	a.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &Area{})
}
